package com.ideal.manage.esms.controller.project;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ideal.manage.esms.bean.DTO.PageDto;
import com.ideal.manage.esms.bean.project.UserManage;
import com.ideal.manage.esms.service.monitor.MonitorService;
import com.ideal.manage.esms.service.project.ProjectService;
import com.ideal.manage.esms.service.system.ParameterService;
import com.ideal.manage.esms.service.system.RoleMenuService;
import com.ideal.manage.esms.service.system.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 83730 on 2018/4/17.
 */
@Controller
@RequestMapping("project/userManage")
public class UserManageController {
    @Resource
    private ProjectService projectService;
    @Resource
    private RoleService roleService;
    @Resource
    private ParameterService parameterService;
    @Resource
    private RoleMenuService roleMenuService;

    @Resource
    private MonitorService monitorService;


    @RequestMapping("user_list")
    public void userList(Model model) {
        System.out.println(1111);
    }

    @RequestMapping("user_data")
    @ResponseBody
    public PageDto userData(int pageNum, HttpServletRequest request) {
        List<UserManage> manages = new ArrayList<>();

        UserManage manage = new UserManage();
        manage.setName("Admin");
        manage.setNumber("U001");
        manage.setCreateUser("系统");
        manage.setModificationPassword("xxxxxxx");
        manage.setOnloadTime("");
        manage.setPassword("xxx");
        manage.setPermissionAssignment("0123");
        manage.setType("超级管理员");
        manage.setProject("所有");

        UserManage manage1 = new UserManage();
        manage1.setName("Admin123");
        manage1.setNumber("U002");
        manage1.setCreateUser("Admin");
        manage1.setModificationPassword("xxxx");
        manage1.setOnloadTime("");
        manage1.setPassword("xxx");
        manage1.setPermissionAssignment("0123");
        manage1.setType("高级管理员");
        manage1.setProject("大拇指广场");

        manages.add(manage);
        manages.add(manage1);

        PageDto pageDto = new PageDto();
        pageDto.setRows(manages);
        pageDto.setTotal(2L);
        return pageDto;
    }

    @RequestMapping("user_add")
    public void userAdd(Model model) {
        System.out.println(1111);
    }

    @RequestMapping("user_edit")
    public void userEdit(Model model) {
        System.out.println(1111);
    }


    @RequestMapping("deploy_edit_data")
    @ResponseBody
    public JSONArray deployEditData(Long id,Model model) {
        JSONArray list = new JSONArray();
        JSONObject jsonObject;
        for (int i = 1; i < 5; i++) {
            jsonObject = new JSONObject();
            // 假装一下null
            jsonObject.put("id", i);
            jsonObject.put("name", "比亚迪");
            jsonObject.put("pid", "type");
            list.add(jsonObject);
        }
        return list;
    }
}
